//查询字符串转换成对象 
let String = {
    query:function(str){
        let obj = {}
        if(str.indexOf('?',0) === -1){
           str.split('&').forEach( item => {
             let arr = item.split('=')
              obj[arr[0]] = arr[1]
            })
            console.log(obj);
        }else {
            str.slice(1).split('&').forEach( item => {
                let arr = item.split('=')
                obj[arr[0]] = arr[1]
            })
            console.log(obj);
        }
    }
}
const str = '?id=1&name=lisi&age=18'
String.query(str)



//函数
function query(str){
    let obj = {}
    if(str.indexOf('?',0) === -1){
       str.split('&').forEach( item => {
         let arr = item.split('=')
          obj[arr[0]] = arr[1]
        })
        console.log(obj);
    }else {
        str.slice(1).split('&').forEach( item => {
            let arr = item.split('=')
            obj[arr[0]] = arr[1]
        })
        console.log(obj);
    }
}